package com.hp.attendance.serlvet.leave;

import com.hp.attendance.entity.Leave;
import com.hp.attendance.entity.dto.ExcelDTO;
import com.hp.attendance.service.ExcelService;
import com.hp.attendance.service.LeaveService;
import com.hp.attendance.util.ExcelUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/exportLeave")
public class LeaveExportExcelServlet extends HttpServlet {
    private LeaveService leaveService = new LeaveService();
    private ExcelService excelService = new ExcelService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //导出请假记录
        try {
            List<ExcelDTO> liseExcel = excelService.getList("lea");
            List<Leave> list = leaveService.getList();
            ExcelUtil.exportExcel(list,liseExcel,resp,"请假信息统计.xlsx");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
